package com.java110.mall.cart.bmo.housekeepingFeeConfig.impl;

import com.java110.mall.cart.bmo.housekeepingFeeConfig.IGetHousekeepingFeeConfigBMO;
import com.java110.dto.housekeeping.HousekeepingFeeTypeDto;
import com.java110.dto.housekeeping.HousekeepingServFeeDto;
import com.java110.intf.cart.IHousekeepingFeeConfigInnerServiceSMO;
import com.java110.intf.cart.IHousekeepingFeeTypeInnerServiceSMO;
import com.java110.intf.cart.IHousekeepingServFeeInnerServiceSMO;
import com.java110.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import com.java110.dto.housekeeping.HousekeepingFeeConfigDto;


import java.util.ArrayList;
import java.util.List;

@Service("getHousekeepingFeeConfigBMOImpl")
public class GetHousekeepingFeeConfigBMOImpl implements IGetHousekeepingFeeConfigBMO {

    @Autowired
    private IHousekeepingFeeConfigInnerServiceSMO housekeepingFeeConfigInnerServiceSMOImpl;
    @Autowired
    private IHousekeepingServFeeInnerServiceSMO housekeepingServFeeInnerServiceSMOImpl;
    @Autowired
    private IHousekeepingFeeTypeInnerServiceSMO housekeepingFeeTypeInnerServiceSMOImpl;
    /**
     *
     *
     * @param  housekeepingFeeConfigDto
     * @return 订单服务能够接受的报文
     */
    public ResponseEntity<String> get(HousekeepingFeeConfigDto housekeepingFeeConfigDto) {


        int count = housekeepingFeeConfigInnerServiceSMOImpl.queryHousekeepingFeeConfigsCount(housekeepingFeeConfigDto);

        List<HousekeepingFeeConfigDto> housekeepingFeeConfigDtos = null;
        if (count > 0) {
            housekeepingFeeConfigDtos = housekeepingFeeConfigInnerServiceSMOImpl.queryHousekeepingFeeConfigs(housekeepingFeeConfigDto);
        } else {
            housekeepingFeeConfigDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) housekeepingFeeConfigDto.getRow()), count, housekeepingFeeConfigDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

    @Override
    public ResponseEntity<String> getServFee(HousekeepingServFeeDto housekeepingServFeeDto) {

        int count = housekeepingServFeeInnerServiceSMOImpl.queryHousekeepingServFeesCount(housekeepingServFeeDto);

        List<HousekeepingServFeeDto> housekeepingServFeeDtos = null;
        if (count > 0) {
            housekeepingServFeeDtos = housekeepingServFeeInnerServiceSMOImpl.queryHousekeepingServFees(housekeepingServFeeDto);
        } else {
            housekeepingServFeeDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) housekeepingServFeeDto.getRow()), count, housekeepingServFeeDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

    @Override
    public ResponseEntity<String> getServFeeConfig(HousekeepingServFeeDto housekeepingServFeeDto) {

        int count = housekeepingServFeeInnerServiceSMOImpl.queryHousekeepingServFeesCount(housekeepingServFeeDto);

        List<HousekeepingFeeTypeDto> housekeepingFeeTypeDtos = null;
        int page = housekeepingServFeeDto.getPage();
        int row = housekeepingServFeeDto.getRow();
        if (count > 0) {
            housekeepingFeeTypeDtos = housekeepingFeeTypeInnerServiceSMOImpl.queryHousekeepingServFeeTypes(housekeepingServFeeDto);
            if(null != housekeepingFeeTypeDtos && housekeepingFeeTypeDtos.size()>0){
                for(HousekeepingFeeTypeDto housekeepingFeeTypeDto:housekeepingFeeTypeDtos){
                    housekeepingServFeeDto.setPage( page );
                    housekeepingServFeeDto.setRow( row );
                    housekeepingServFeeDto.setFeeTypeCd( housekeepingFeeTypeDto.getFeeTypeCd() );
                    List<HousekeepingFeeConfigDto> housekeepingFeeConfigDtos = housekeepingFeeConfigInnerServiceSMOImpl.queryHousekeepingServFeeConfigs( housekeepingServFeeDto );
                    housekeepingFeeTypeDto.setHousekeepingFeeConfigs( housekeepingFeeConfigDtos );
                }
            }

        } else {
            housekeepingFeeTypeDtos = new ArrayList<>();
        }

        ResultVo resultVo = new ResultVo((int) Math.ceil((double) count / (double) housekeepingServFeeDto.getRow()), count, housekeepingFeeTypeDtos);

        ResponseEntity<String> responseEntity = new ResponseEntity<String>(resultVo.toString(), HttpStatus.OK);

        return responseEntity;
    }

}
